/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Grafik;

import java.awt.Component;
import java.util.Arrays;
import javax.swing.JFrame;

/**
 *
 * @author Charles Thillemann Hemmingsen s122801
 */
public class Opsæt extends javax.swing.JPanel
{

    //HovedPanel hovedPanel;
    public MainSkærm ejer;

    public void setEjer(MainSkærm ejer)
    {
        this.ejer = ejer;
    }

    /**
     * Creates new form Opsæt
     */
    public Opsæt()
    {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        opretKodeordField2 = new javax.swing.JPasswordField();
        opretKodeButton = new javax.swing.JButton();
        opretKodeordField1 = new javax.swing.JPasswordField();
        jLabel4 = new javax.swing.JLabel();
        opretKodeordErrorLabel = new javax.swing.JLabel();

        setLayout(null);

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 32)); // NOI18N
        jLabel2.setText("<html><center>Velkommen til<br>SmartHome </center> </html>");
        add(jLabel2);
        jLabel2.setBounds(130, 20, 240, 110);

        jLabel3.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        jLabel3.setText("Gentag Kodeord:");
        add(jLabel3);
        jLabel3.setBounds(20, 330, 150, 24);

        opretKodeordField2.setText("jPasswordField1");
        add(opretKodeordField2);
        opretKodeordField2.setBounds(180, 330, 111, 20);

        opretKodeButton.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        opretKodeButton.setText("Opret");
        opretKodeButton.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                opretKodeButtonActionPerformed(evt);
            }
        });
        add(opretKodeButton);
        opretKodeButton.setBounds(180, 400, 150, 64);

        opretKodeordField1.setText("jPasswordField1");
        add(opretKodeordField1);
        opretKodeordField1.setBounds(180, 270, 111, 20);

        jLabel4.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        jLabel4.setText("Opret Kodeord:");
        add(jLabel4);
        jLabel4.setBounds(20, 270, 150, 24);

        opretKodeordErrorLabel.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        opretKodeordErrorLabel.setForeground(new java.awt.Color(255, 0, 51));
        opretKodeordErrorLabel.setText("Kodeordene skal være ens!");
        add(opretKodeordErrorLabel);
        opretKodeordErrorLabel.setBounds(130, 220, 240, 24);
        opretKodeordErrorLabel.setVisible(false);
    }// </editor-fold>//GEN-END:initComponents

    private void opretKodeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opretKodeButtonActionPerformed
        if (Arrays.equals(opretKodeordField1.getPassword(), opretKodeordField2.getPassword()))
        {
            ejer.kodeord = opretKodeordField1.getPassword();

            // Rykker hovedpanel til øverste lag
            ejer.hovedPanel.setVisible(true);
            ejer.rykForest(ejer.hovedPanel);

            // Gør opsætning usynlig
            this.setVisible(false);

        } else
        {
            opretKodeordErrorLabel.setVisible(true);
        }

    }//GEN-LAST:event_opretKodeButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JButton opretKodeButton;
    private javax.swing.JLabel opretKodeordErrorLabel;
    private javax.swing.JPasswordField opretKodeordField1;
    private javax.swing.JPasswordField opretKodeordField2;
    // End of variables declaration//GEN-END:variables
}
